package com.yan.demo;

import com.yan.domain.Rectangle;

import java.util.Random;

public class Demo5 {
    public static void main(String[] args) {
        Random r = new Random();
        Rectangle[] arr = new Rectangle[5];
        /*double a = r.nextDouble(9) + 1;
        double b = r.nextDouble(9) + 1;*/
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new Rectangle();
            arr[i].setChang(r.nextDouble(9) + 1);
            arr[i].setKuan(r.nextDouble(9) + 1);
        }
        for (Rectangle a : arr) {
            System.out.println(a.getInfo());
        }

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if(arr[j].getArea() > arr[j+1].getArea()){
                    Rectangle temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j+1] = temp;
                }
            }
        }
        System.out.println("-------------------------------------------------------------------------");
        for (Rectangle a : arr) {
            System.out.println(a.getInfo());
        }


    }
}
